473,441 Members | 1,851 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Javascript Multiple select menu

hi,
iam creating a multiselect menu in javascript the code for that is as
follows
"<select id=\"groups\" name=\"groups[]\" size=\"4\" multiple>"
"<option value=x>xyz</option>"
..
..
..
..
"</select>"
iam doing this completely in javascript. Its a dynamic menu. So how can
retrieve the values in javascript itself . if anyone knows kindly let
me know

Aug 1 '06 #1
1 6741

kiran wrote:
hi,
iam creating a multiselect menu in javascript the code for that is as
follows
"<select id=\"groups\" name=\"groups[]\" size=\"4\" multiple>"
"<option value=x>xyz</option>"
.
.
.
.
"</select>"
iam doing this completely in javascript. Its a dynamic menu. So how can
retrieve the values in javascript itself . if anyone knows kindly let
me know
try this:
<script>
var dynamicOpts = new Array(
new Option("xyz", "x"),
new Option("yzx", "y"),
new Option("zxy", "z"),
new Option("foo", "f"),
new Option("bar", "r"),
new Option("baz", "b")
);

function makeSelect(){
var theSelect = window.document.createElement("select");
arguments.callee.theSelect = theSelect;
theSelect.id = "groups";
theSelect.name = "groups[]";
theSelect.size = "4";
theSelect.multiple = "multiple";
var theOptions = theSelect.options;
for(var i=0;i<dynamicOpts.length;i++){
theOptions[theOptions.length] = dynamicOpts[i];
}
document.getElementById("genContFrm").appendChild( theSelect);
}
function showSelected(){
var opts = makeSelect.theSelect.options;
var selVals = "";
for(var i=0; i<opts.length;i++){
if(opts[i].selected){
selVals += opts[i].value + ",";
}
}
alert(selVals);
}
window.onload = makeSelect;

</script>

<form id="genContFrm">
<input type="button" onclick="showSelected()" value="show selected" />
</form>

Aug 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: JesusFreak | last post by:
From: us_traveller@yahoo.com (JesusFreak) Newsgroups: microsoft.public.scripting.jscript Subject: toolbar script problem NNTP-Posting-Host: 192.92.126.136 Recently, I downloaded the following...
6
by: phpnewbie26 | last post by:
My current form has one multiple select drop down menu as well as few other drop down menus that are single select. Originally I had it so that the multiple select menu was first, but this created...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.